package a1_p04_jw_kw.junit;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.HashMap;
import org.jgrapht.Graph;
import org.jgrapht.graph.DefaultWeightedEdge;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import a1_p04_jw_kw.graph.GraphCreater;
import a1_p04_jw_kw.graph.GraphParser;
import a1_p04_jw_kw.struct.GraphSetup;
import a1_p04_jw_kw.struct.GraphTransition;
import a1_p04_jw_kw.struct.Node;

public class IOTest {

	Graph<Node, DefaultWeightedEdge> graph;
	Graph<Node, DefaultWeightedEdge> testGraph;
	
	public IOTest() {
		this.graph = null;
		this.testGraph = null;
	}

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
		// setup GKA1 Nodes
		String[] nodes = new String[] {"a", "b", "c","d","e","f","g","h","i","j","k"};
		HashMap<String, Node> vertixes = new HashMap<String, Node>();
		
		for (String nodeName : nodes) {
			Node newNode = new Node(nodeName);
			vertixes.put(nodeName, newNode);
		}
		
		// setup GKA1 Transitions
		ArrayList<GraphTransition> transitions = new ArrayList<GraphTransition>();
		
		ArrayList<String[]> transNames = new ArrayList<String[]>();
		transNames.add(new String[]{"a", "b"});
		transNames.add(new String[]{"a", "c"});
		transNames.add(new String[]{"a", "h"});
		transNames.add(new String[]{"a", "k"});
		
		transNames.add(new String[]{"b", "b"});
		transNames.add(new String[]{"b", "j"});
		transNames.add(new String[]{"b", "k"});
		transNames.add(new String[]{"b", "i"});
		
		transNames.add(new String[]{"c", "a"});
		transNames.add(new String[]{"c", "d"});
		
		transNames.add(new String[]{"d", "a"});
		transNames.add(new String[]{"d", "e"});
		transNames.add(new String[]{"d", "k"});
		
		transNames.add(new String[]{"e", "b"});
		transNames.add(new String[]{"e", "c"});
		transNames.add(new String[]{"e", "e"});
		transNames.add(new String[]{"e", "f"});
		
		transNames.add(new String[]{"f", "c"});
		transNames.add(new String[]{"f", "g"});
		
		transNames.add(new String[]{"g", "g"});
		transNames.add(new String[]{"g", "e"});
		transNames.add(new String[]{"g", "b"});
		transNames.add(new String[]{"g", "d"});
		
		transNames.add(new String[]{"h", "b"});
		transNames.add(new String[]{"h", "c"});
		
		transNames.add(new String[]{"i", "a"});
		transNames.add(new String[]{"i", "c"});
		transNames.add(new String[]{"i", "i"});
		
		transNames.add(new String[]{"j", "k"});
		transNames.add(new String[]{"j", "c"});
		transNames.add(new String[]{"j", "a"});
		transNames.add(new String[]{"j", "b"});
		
		transNames.add(new String[]{"k", "c"});
		transNames.add(new String[]{"k", "g"});
		transNames.add(new String[]{"k", "d"});
		
		//setup graph
		for (String[] nodeTrans : transNames) {
			transitions.add(new GraphTransition(vertixes.get(nodeTrans[0]), vertixes.get(nodeTrans[1])));
		}
		GraphSetup gs = new GraphSetup(true, false, false, false, transitions);
		GraphCreater gc = new GraphCreater(gs);
		gc.createGraph();
		graph= gc.getGraph();
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testCreateGraph() {
		//create the graph as JGraphT graph
		GraphParser gp = new GraphParser("gka1.gka");

		GraphCreater gc = new GraphCreater(gp.getGraphSetup());
		gc.createGraph();
		
		//add the JGraphT graph to the JGraph adapter
		testGraph = gc.getGraph();
		
		assertTrue("graph shouldnt be null", graph!=null);

	}

}
